﻿module Output


open System
open System.IO
open Tokens
open ParsingEvents
open ExecutionEvents


let CreateConsoleTextOutput() =
   let context = ExecutionTrigger()
 
   context.OnExecutionEnded.Add(fun () -> printfn "Execution completed.")
   context.OnExecutionStarted.Add(fun () -> printfn "Execution started...")
   
   context.OnFeatureEnded.Add(fun (f) -> 
      if (f.Succeded) then printfn "  Feature completed successfully." else printfn @"  Feature failed.\r\n"; f.Succeded <- true
      )

   context.OnFeatureStarted.Add(fun (f) -> 
      printfn "  %s %s" f.Section.Keyword.Source  f.Section.Description.Source; f.Succeded <- true
      )

   context.OnScenarioEnded.Add(fun (s) -> 
      if (s.Succeded) then printfn "    Scenario completed successfully." else printfn @"    Scenario failed.\r\n"; s.Succeded <- true
      )

   context.OnScenarioStarted.Add(fun (s) -> 
      printfn "    %s %s" s.Section.Keyword.Source  s.Section.Description.Source; s.Succeded <- true
      )

   context.OnStepEnded.Add(fun (s) -> 
      if (s.Succeded) then printfn "      Step completed successfully." else printfn @"      Step failed.\r\n"; s.Succeded <- true
      )

   context.OnStepStarted.Add(fun (s) -> 
      printfn "      %s %s" s.Section.Keyword.Source (ToString(s.Section.Instructions)); s.Succeded <- true
      )

   context.OnParsingError.Add(fun (e) -> 
      printfn "%A" e.Location; printfn "%s" e.Error.Message; printfn "%s" e.Error.StackTrace
      )

   context

let CreateOutput(kind : string) =
   match (kind) with
   | _ -> CreateConsoleTextOutput()